
import api from "../api/api"
export default {

    data() {
        return {
            tableData: [],
            page: 1,
            size: 15,
            totalCount: -1,
            tableHeight: '-1px'
        }
    },
    created() {
        this.getData(this.indexurl);
    },
    mounted() {
        this.getHeight()
        //增加监听事件，窗口变化时得到高度。
        window.addEventListener('resize', this.getHeight, false)
    },
    methods: {
        //获取浏览器高度并计算得到表格所用高度。
        getHeight() {
            this.tableHeight = document.getElementsByClassName("workshops_main")[0].offsetHeight - 100 + 'px'
            console.log(this.tableHeight, 789)
        },
        //获取分页数据
        getData(url) {
            api[url]({
                page: this.page,
                size: this.size
            }).then(res => {
                this.tableData = res.data.list
                this.totalCount = res.data.pagination.total
            })
        },
        //搜索
        SearchMthods(params){
            this.page =1
            api[this.indexurl]({
                ...params,
            }).then(res=>{
                this.tableData = res.data.list
                this.totalCount = res.data.pagination.total
            })
        },
        //重置
        resetMethods(){
            this.page =1
            this.getData(this.indexurl)
        },
        //删除
        delHandle(data) {
            console.log(data,666)
            this.$confirm("此操作将永久删除记录, 是否继续?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                api[this.delurl]({
                    ids:[data.id]
                }).then((res) => {
                    if (res.code == 1000) {
                        this.$message({
                            type: "success",
                            message: "删除成功!",
                        });
                        this.getData(this.indexurl)
                    }else{
                        this.$message({
                            type: "warning",
                            message: res.message,
                        });
                    }
                });
            });
        },
        //分页 改变当前页
        currentchange(val) {
            this.page = val
            this.getData(this.indexurl)
        },
        //tab切换
        handleTabClick(){
            console.log(123)
        }

    },
    watch: {

    }
}